
#ifndef OS_MUTEX_H
#define OS_MUTEX_H

#include "os_cfg.h"
#include "os_event.h"
#include "os_task.h"

/**
 * 浜掓枼淇″彿閲�
 */
typedef struct  _os_mutex_t {
    os_event_t event;               // 浜嬩欢鎺у埗鍧�
    os_task_t * owner;              // 鎷ユ湁鑰�
    uint16_t locked_cnt;            // 閿佸畾娆℃暟
    uint8_t raw_prio;               // 鎷ユ湁鑰呭師濮嬩紭鍏堢骇
}os_mutex_t;

os_err_t os_mutex_init (os_mutex_t * mutex);
os_err_t os_mutex_uninit (os_mutex_t * mutex);       
os_mutex_t * os_mutex_create (void);
os_err_t os_mutex_free (os_mutex_t * mutex);
os_err_t os_mutex_lock (os_mutex_t * mutex, int ms);
os_err_t os_mutex_unlock (os_mutex_t * mutex);
uint16_t os_mutex_lock_cnt (os_mutex_t * mutex);
uint16_t os_mutex_task_cnt (os_mutex_t * mutex);
os_task_t * os_mutex_owner (os_mutex_t * mutex);

#endif /* TMUTEX_H */
